//app.js
var util = require('./utils/util');
App({
    onLaunch: function() {
        // 展示本地存储能力
        var logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs)

        // 登录
        wx.login({
            success: res => {
                // 发送 res.code 到后台换取 openId, sessionKey, unionId
            }
        })
    },

	// 验证是否登陆
	checkLogin: function (callback) {
		var that = this;
		util.showLoading();
		if (wx.getStorageSync('store_id') != '') {
			if (typeof callback == 'function') {
				util.hideLoading();
				callback();
			}
		} else {
			util.hideLoading();
			wx.removeStorageSync('store_id');
			util.message('您未登录,请先登录', function () {
				var pages = getCurrentPages()
				console.log(pages);
				var back_url = pages[pages.length-1].route;
				console.log(back_url);
				wx.redirectTo({
					url: '/pages/login/login?back_url='+back_url,
				})
			})
			return false;
		}
	},

	globalData: {
		userInfo: null,
		http_url: "https://www.tglq.top/index.php/",
	}
})